<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Progressbar</title>
    <style>
        .box{
            width: 400px;
            height: 40px;
            border: 1px solid red;
            margin-bottom: 10px;
        }
        #num{
            width: 0;
            height: 40px;
            line-height: 40px;
            text-align: center;
            background-color: deeppink;
        }
    </style>
</head>
<body>
<div class="box">
    <div id="num">
        <span>0</span><span>%</span>
    </div>
</div>
<button id="but" >安装</button>
<script>
   var bt= document.getElementById("but").onclick=function () {
        let spans = document.getElementsByTagName('span');
        var count = spans[0];
        let num=document.getElementById("num")
        var i=0;

        var timer=window.setInterval(function () {
            i+=10;
            count.innerText=Math.round(i*100/400);
            num.style.width=i+'px'
            if (i == 400) {
                clearInterval(timer)
            }

        },200)
    }
</script>
</body>
</html>